#include "Method.h"
#include <cfloat>
#include <limits>

double func1(double x){
  return 1/x - tan(x);
}

double func2(double x){
  return 1/x - pow(2,x);
}

double func3(double x){
  return pow(2,-x) + exp(x) + 2*cos(x) - 6;
}

double func4(double x){
  double fac = x*x*x + 4*x*x + 3*x + 5;
  double den = 2*x*x*x - 9*x*x + 18*x -2;
  return fac/den;
}

int main(int argc, char* argv[]){
  double (*pf[4])(double) = {&func1,&func2,&func3,&func4};
  Bisection<double> BstSolver(100,1e-6,pf[0],DBL_MIN,PI/2,1e-8);
  double result,error = 0;
  if (BstSolver.Is_proper()){
    result = BstSolver.solve();
    error = (*pf[0])(result);
    cout << "Problem 1: x = " << result << ", absolute error r = " << error << endl;
  }
  else
    cout << "Problem 1: Error! The problem is not proper!" << endl;
  BstSolver.set_function(pf[1]);
  BstSolver.set_right(1);
  if (BstSolver.Is_proper()){
    result = BstSolver.solve();
    error = (*pf[1])(result);
    cout << "Problem 2: x = " << result << ", absolute error r = " << error << endl;
  }
  else
    cout << "Problem 2: Error! The problem is not proper!" << endl;
  BstSolver.set_function(pf[2]);
  BstSolver.set_left(1);
  BstSolver.set_right(3);
  if (BstSolver.Is_proper()){
    result = BstSolver.solve();
    error = (*pf[2])(result);
    cout << "Problem 3: x = " << result << ", absolute error r = " << error << endl;
  }
  else
    cout << "Problem 3: Error! The problem is not proper!" << endl;
  BstSolver.set_function(pf[3]);
  BstSolver.set_left(0);
  BstSolver.set_right(4);
  if (BstSolver.Is_proper()){
    result = BstSolver.solve();
    error = (*pf[3])(result);
    cout << "Problem 4: x = " << result << ", absolute error r = " << error << endl;
  }
  else
    cout << "Problem 4: Error! The problem is not proper!" << endl;
}
